import axios from "../axios/index";
import {stringify} from "qs";

// 通用请求方法
// 查 -- 分页
export const getPageApi = (url, params) => {
    const {formData, pagination} = params;
    let queryItems = {};
    if (pagination) {
        const {current} = pagination;
        const size = pagination.pageSize;
        Object.assign(queryItems, {current, size});
    }

    Object.assign(queryItems, formData);
    return axios.post(url, queryItems);
};
// 查 -- 详情
export const getDetailApi = (url, id) => axios.get(`${url}/${id}`);

// 删 -- 单条
export const deleteDetailApi = (url, id, params) => axios.delete(`${url}/${id}`, {data: params});

// 增
export const postDetailApi = (url, params) => {
    return axios.post(url, params);
};
// 改
export const putDetailApi = (url, params) => {
    return axios.put(url, params);
};

// 各页面请求方法

/* *************************** 菜单 ***********************/
export const menuApi = {};
// 分页  /cd/selectPage
menuApi.getPage = (params) => getPageApi("cd/selectPage", params);

// 查 /cd/selectById/{id}
menuApi.get = (id) => getDetailApi("cd/selectById", id);

// 删 /cd/delete/{id}
menuApi.delete = (id) => deleteDetailApi("cd/delete", id);

// 增 /cd/createCdb
menuApi.post = (params) => postDetailApi("cd/createCdb", params);

// 改 /cd/update
menuApi.put = (params) => putDetailApi("cd/update", params);

// 查询全部的菜单节点树 /cd
menuApi.getAll = () => axios.get("cd");

// 查询菜单的按钮权限 /cd/selectBtn/{id}
menuApi.getBtns = (id) => axios.get(`cd/selectBtn/${id}`);

// 查询菜单左侧菜单 /cd/selectCd
menuApi.getLeftMenu = () => axios.get("/cd/selectCd");

// 查询父级菜单 cd/selectParent/{dj}
menuApi.getParent = (dj) => axios.get(`cd/selectParent/${dj}`);

/* *************************** 系统参数 ***********************/
export const systemParaApi = {};
// 分页  xtcs/xtcsList
systemParaApi.getPage = (params) => getPageApi("xtcs/xtcsList", params);

// 查
systemParaApi.get = (id) => getDetailApi("xtcs", id);

// 删
systemParaApi.delete = (id) => deleteDetailApi("xtcs", id);

// 增 /xtcs/createXtcs
systemParaApi.post = (params) => postDetailApi("xtcs/createXtcs", params);

// 改 /xtcs/updateXtcs
systemParaApi.put = (params) => putDetailApi("xtcs/updateXtcs", params);

// 查询系统编号 /xtcs/queryNumber/{csbm}
systemParaApi.getSystemNum = (csbm) => axios.get(`xtcs/queryNumber/${csbm}`);

/* *************************** 数据字典 ***********************/
export const dataBookApi = {};
// 分页 /sjzd/selectPage
dataBookApi.getPage = (params) => getPageApi("sjzd/selectPage", params);

// 查  /sjzd/selectById/{id}
dataBookApi.get = (id) => getDetailApi("sjzd/selectById", id);

// 删   /sjzd/delete/{id}
dataBookApi.delete = (id) => deleteDetailApi("sjzd/delete", id);

// 增   /sjzd/createSjzd
dataBookApi.post = (params) => postDetailApi("sjzd/createSjzd", params);

// 改 /sjzd/updateSjzd
dataBookApi.put = (params) => putDetailApi("sjzd/updateSjzd", params);

// 数据字典搜索（科室 只查体检的） POST  /sjzd/selectSjzdByLx
dataBookApi.getByLx = (params) => axios.post("sjzd/selectSjzdByLx", params);

// 数据字典类型搜索 GET /sjzd/zdlxdm stringify
dataBookApi.getByDm = (params) => axios.get(`sjzd/zdlxdm?${stringify(params)}`);

/* *************************** 用户组 ***********************/
export const userGroupApi = {};
// 分页 /yhz/yhzList
userGroupApi.getPage = (params) => getPageApi("yhz/yhzList", params);

// 查  /yhz/{id}
userGroupApi.get = (id) => getDetailApi("yhz", id);

// 删   /yhz/deleteYhz/{id}
userGroupApi.delete = (id) => deleteDetailApi("yhz/deleteYhz", id);

// 增   /yhz/createYhz
userGroupApi.post = (params) => postDetailApi("yhz/createYhz", params);

// 改   /yhz/updateYhz
userGroupApi.put = (params) => putDetailApi("yhz/updateYhz", params);

// 分页查询 (下拉框使用)  yhzmc:可模糊   /yhz/selectPage
userGroupApi.getSelectOption = (params) => axios.post("yhz/selectPage", params);

/* *************************** 用户、 ***********************/
export const userApi = {};
// 分页 /user/selectYhPage
userApi.getPage = (params) => getPageApi("user/selectYhPage", params);

// 查  /user/selectYhById/{id}
userApi.get = (id) => getDetailApi(`user/selectYhById`, id);

// 删  /user/delYh/{id}
userApi.delete = (id) => deleteDetailApi(`user/delYh`, id);

// 增  /user/createYh
userApi.post = (params) => postDetailApi("user/createYh", params);

// 改  /user/updateYhInfo
userApi.put = (params) => putDetailApi("user/updateYhInfo", params);

// 根据医院id查询所有的用户 /user/selectYhByYyId/{yyid}
userApi.getAllByYyid = (yyid) => axios.get(`user/selectYhByYyId/${yyid}`);

// 用户名查询 /user/selectYhbh/{yhbh}
userApi.getYhbh = (yhbh) => axios.get(`user/selectYhbh/${yhbh}`);

// 查询密码是否正确 GET  /user/isValidPassWord
userApi.getValidPassWord = () => axios.get("user/isValidPassWord");

// 修改密码 PUT /user/updatePassWord
userApi.putPassWord = (params) => axios.put("user/updatePassWord", params);

/* *************************** 行政区划 ***********************/
export const admDivisionApi = {};
// 分页  /xzqh/xzqhList
admDivisionApi.getPage = (params) => getPageApi("xzqh/xzqhList", params);

// 查  /xzqh/{id}
admDivisionApi.get = (id) => getDetailApi("xzqh", id);

// 删  /xzqh/{id}
admDivisionApi.delete = (id) => deleteDetailApi("xzqh", id);

// 增 /xzqh
admDivisionApi.post = (params) => postDetailApi("xzqh", params);

// 改 /xzqh
admDivisionApi.put = (params) => putDetailApi("xzqh", params);

// 查找行政区划 下拉列表或详情 Xzqh 表  post /xzqh/find
admDivisionApi.find = (params) => axios.post("xzqh/find", params);

/* *************************** 医院科室 ***********************/
export const departmentsApi = {};
// 分页 /ks/selectPage
departmentsApi.getPage = (params) => getPageApi("ks/selectPage", params);

// 查 /ks/{id}
departmentsApi.get = (id) => getDetailApi("ks", id);

// 删 /ks/{id}
departmentsApi.delete = (id) => deleteDetailApi("ks", id);

// 增 /ks
departmentsApi.post = (params) => postDetailApi("ks", params);

// 改 /ks
departmentsApi.put = (params) => putDetailApi("ks", params);

// 根据医院id 查询所有的 科室id和名称  get /ks/selectAllKs/{id}
departmentsApi.getAllYyks = (id) => axios.get(`/ks/selectAllKs/${id}`);

// 分页 /gs/selectPage
departmentsApi.search = (params) => axios.post("ks/search", params);

/* *************************** 个人信息 ***********************/
export const personalApi = {};
// 分页 /ks/selectPage
personalApi.getPage = (params) => getPageApi("bjgl/grxx/selectPage", params);

// 查 /ks/{id}
personalApi.get = (id) => getDetailApi("bjgl/grxx/selectGrxx", id);

// 删 /ks/{id}
personalApi.delete = (id) => deleteDetailApi("bjgl/grxx/deleteGrxx", id);

// 增 /ks
personalApi.post = (params) => postDetailApi("bjgl/grxx/createGrxx", params);

// 改 /ks
personalApi.put = (params) => putDetailApi("bjgl/grxx/updateGrxx", params);

// 根据姓名查询
personalApi.postXm = (xm) => axios.post(`bjgl/grxx/listByXm?xm=${xm}`, xm);

// 打印
personalApi.DY = (id) => getDetailApi("bjgl/grxx/grxxFz", id)
// 首页报表每月建档统计
personalApi.getJD = () => axios.post("bjgl/grxx/mytj");
// 首页报表年龄段统计
personalApi.getNL = () => axios.post("bjgl/grxx/nltj");
// 首页报表年龄段统计
personalApi.getGG = () => axios.post("gg/shouye", "{}");
// 首页报表年龄段统计
personalApi.getZH = () => axios.post("bjgl/grxx/zhtj");
// 销售统计
personalApi.getSale = () => axios.post("bjgl/grxx/xstj");


/* *************************** 员工信息 ***********************/
export const ygxxApi = {};
// 分页 /ygxx/selectPage
ygxxApi.getPage = (params) => getPageApi("pccb/ygxx/selectPage", params);

// 查 /ygxx/{id}
ygxxApi.get = (id) => getDetailApi("pccb/ygxx/", id);

// 分页 /gs/selectPage
// 所有search、next接口，传状态标志ztbz:1, 仅新增时的客服销售传是否在线sfzx:1
ygxxApi.search = (params) => axios.post("pccb/ygxx/search", {
    ztbz: 1,
    ...params
});
// ygxxApi.newSearch = (params) => axios.post("pccb/ygxx/next", {
// 	ztbz: 1,
// 	sfzx:1,
// 	...params
// });
// 增 /ygxx
ygxxApi.post = (params) => postDetailApi("pccb/ygxx/createYgxx", params);

// 删 /ks/{id}
ygxxApi.delete = (id) => deleteDetailApi("pccb/ygxx/delYgxx", id);

// 改 /ks
ygxxApi.put = (params) => putDetailApi("pccb/ygxx/updateYgInfo", params);
// 查询联系方式 三天内重复，然后返回人员列表
ygxxApi.searchCf = (params) => axios.post("pccb/ygxx/searchCf", params);

// 计划查询，用于表单的下拉选项查询，先不动
ygxxApi.getPromotes = (params) => axios.post("pccb/ygxx/getJh", params);
export const jhApi = {
    // 查询计划（分页）
    getJh: (params) => getPageApi("jh/getJh", params),
    // 查询计划（单条）
    getJhById: (id) => getDetailApi("jh", id),
    // 新增计划
    createJh: (params) => postDetailApi("jh/createJh", params),
    // 修改计划
    updateJh: (params) => putDetailApi("jh/updateJh", params),
    search: (params) => axios.post("jh/getzhxx", params),
    deleteJh: (id) => deleteDetailApi("jh", id)
}

// 自动分配
export const zdfpApi = {
    // 分页查询
    selectPage: (params) => getPageApi("pccb/zdfp/selectPage", params),
    // 查单条
    getFpById: (id) => getDetailApi("pccb/zdfp", id),
    // 增
    createFp: (params) => postDetailApi("pccb/zdfp/createZdfp", params),
    // 修改
    updateFp: (params) => putDetailApi("pccb/zdfp/updateZdfp", params),
    // 删
    deleteFp: (id) => deleteDetailApi("pccb/zdfp", id)
}


export const lzApi = {};
// 分页
lzApi.getPage = (params) => getPageApi("pccb/lz/selectPage", params);

// 查
lzApi.get = (id) => getDetailApi("pccb/lz/", id);

// 分页 /gs/selectPage
lzApi.search = (params) => axios.post("pccb/lz/search", params);
// 增 /ygxx
lzApi.post = (params) => postDetailApi("pccb/lz/createLz", params);

// 删 /ks/{id}
lzApi.delete = (id,data) => deleteDetailApi("pccb/lz/delLz", id,data);

// 改 /ks
lzApi.put = (params) => putDetailApi("pccb/lz/updateLzInfo", params);


/* *************************** 每日汇总  ***********************/
export const mrhzApi = {};
// 分页 /mrhz/selectPage
mrhzApi.getPage = (params) => getPageApi("pccb/mrhz/selectPage", params);

// 增 /mrhz/add
mrhzApi.post = (params) => postDetailApi("pccb/mrhz/add", params);

// 分页 /mrhz/selectPage（公司）
mrhzApi.getPagegs = (params) => getPageApi("pccb/mrhz/selectPagegs", params);
// 公司客服统计
mrhzApi.selectPagegsry = (params) => getPageApi("pccb/mrhz/selectPagegsry", params);
mrhzApi.selectPagegsdg = (params) => getPageApi("pccb/mrhz/selectPagegsdg", params);

// 分页 /mrhz/selectPage（公司）
mrhzApi.getPagewx = (params) => getPageApi("pccb/mrhz/selectPagewx", params);

// 分页 /mrhz/selectPage（公司）
mrhzApi.getPagezh = (params) => getPageApi("pccb/mrhz/selectPagezh", params);
// 截止
mrhzApi.mrhzJz = (params) => postDetailApi("/pccb/mrhz/jz", params);

// 成交 弹窗详情
mrhzApi.selectPagecj = (params) => getPageApi("/pccb/lz/selectPagecj", params);
// 修改审核状态
mrhzApi.putSwjz = (params) => putDetailApi("/pccb/lz/putSwjz", params);

// 公司成交统计
mrhzApi.getPagegsxq = (params) => getPageApi("pccb/mrhz/selectPagegsxq", params);
// 审核统计
mrhzApi.getPagesh = (params) => getPageApi("pccb/mrhz/selectPagesh", params);
// 微信成交统计
mrhzApi.selectPagewxcj = (params) => getPageApi("pccb/mrhz/selectPagewxcj", params);
mrhzApi.selectPagewxcjByWxkf = (params) => getPageApi("pccb/mrhz/selectPagewxcjByWxkf", params);
// 抖音统计
mrhzApi.selectPageDy = (params) => getPageApi("pccb/mrhz/selectPagedy", params);

/***      拍摄统计      **/
export const psApi = {
    // 分页查询
    getPage: (params) => getPageApi("pccb/ps/selectPage", params),
    // 新增
    createPs: (params) => postDetailApi("pccb/ps/createPs", params),
    // 查单条
    selectById: (id) => getDetailApi("pccb/ps", id),
    // 编辑
    updatePs: (params) => putDetailApi("pccb/ps/updatePs", params),
    // 删除
    deletePs: (params) => deleteDetailApi("pccb/ps", params),
}

/***      直播统计      **/
export const zbApi = {
    // 分页查询
    getPage: (params) => getPageApi("pccb/zb/selectPage", params),
    // 新增
    createPs: (params) => postDetailApi("pccb/zb/createPs", params),
    // 查单条
    selectById: (id) => getDetailApi("pccb/zb", id),
    // 编辑
    updatePs: (params) => putDetailApi("pccb/zb/updatePs", params),
    // 删除
    deletePs: (params) => deleteDetailApi("pccb/zb", params),
}


/* *************************** 公司信息 ***********************/
export const gsApi = {};
// 分页 /gs/selectPage
gsApi.search = (params) => axios.post("pccb/gs/search", params);


/* *************************** 随访 ***********************/
export const followUpVisitApi = {};
// 分页
followUpVisitApi.getPage = (params) => getPageApi("bjgl/jksf/selectPage", params);
// 查 
followUpVisitApi.get = (id) => getDetailApi("bjgl/jksf/selectJksf/", id);
// 新增
followUpVisitApi.post = (params) => postDetailApi("bjgl/jksf/createJksf", params);
// 删 
followUpVisitApi.delete = (id) => deleteDetailApi("bjgl/jksf/deleteJksf/", id);
// 改 
followUpVisitApi.put = (params) => putDetailApi("bjgl/jksf/updateJksf", params);

/* *************************** 保健人员名单 ***********************/
export const StatementApi = {};
// 分页
StatementApi.getPage = (params) => getPageApi("bjgl/rymd/selectPage", params);
// 查 
StatementApi.get = (id) => getDetailApi("bjgl/rymd/selectRymd/", id);
// 增
StatementApi.post = (params) => postDetailApi("bjgl/rymd/createRymd", params);
// 删 
StatementApi.delete = (id) => deleteDetailApi("bjgl/rymd/deleteRymd/", id);
// 改 
StatementApi.put = (params) => putDetailApi("bjgl/rymd/updateRymd", params);

/* *************************** 专家库 ***********************/
export const expertDatabaseApi = {};
// 分页
expertDatabaseApi.getPage = (params) => getPageApi("bjgl/bjzj/selectPage", params);
// 查 
expertDatabaseApi.get = (id) => getDetailApi("bjgl/bjzj/selectBjzj/", id);
// 新增
expertDatabaseApi.post = (params) => postDetailApi("bjgl/bjzj/createBjzj", params);
// 删 
expertDatabaseApi.delete = (id) => deleteDetailApi("bjgl/bjzj/deleteBjzj/", id);
// 改 
expertDatabaseApi.put = (params) => putDetailApi("bjgl/bjzj/updateBjzj", params);

/* *************************** 转外就诊 ***********************/
export const OutsideDoctorApi = {};
// 分页
OutsideDoctorApi.getPage = (params) => getPageApi("pccb/zwjzjl/selectPage", params);
// 分页
OutsideDoctorApi.search = (params) => axios.post("pccb/zwjzjl/search", params);
// 查 
OutsideDoctorApi.get = (id) => getDetailApi("pccb/zwjzjl/selectZwjzjl", id);
// 新增
OutsideDoctorApi.post = (params) => postDetailApi("pccb/zwjzjl/createZwjzjl", params);
// 删 
OutsideDoctorApi.delete = (id) => deleteDetailApi("pccb/zwjzjl/deleteZwjzjl", id);
// 改 
OutsideDoctorApi.put = (params) => putDetailApi("pccb/zwjzjl/updateZwjzjl", params);

/* *************************** 用药详情 ***********************/
export const MedicationDetailsApi = {};
// 分页
MedicationDetailsApi.getPage = (params) => getPageApi("bjgl/mc/selectPage", params);
// 查 
// MedicationDetailsApi.get = (jzrsh) => getDetailApi("bjgl/yyxq/selectYyxq", jzrsh);
MedicationDetailsApi.get = (jzlsh) => axios.get(`bjgl/yyxq/selectYyxq/${jzlsh}`);
// 新增
MedicationDetailsApi.post = (params) => postDetailApi("bjgl/yyxq/createYyxq", params);
// 删 
MedicationDetailsApi.delete = (jzrsh) => deleteDetailApi("bjgl/yyxq/deleteYyxq", jzrsh);
// 改 
MedicationDetailsApi.put = (params) => putDetailApi("bjgl/yyxq/updateYyxq", params);

/* *************************** 出院小结 ***********************/
export const DischargeAbstractApi = {};
// 分页
DischargeAbstractApi.getPage = (params) => getPageApi("bjgl/cyxj/selectPage", params);
// 查 
// DischargeAbstractApi.get = (id) => getDetailApi("bjgl/cyxj/selectCyxj", id);
DischargeAbstractApi.get = (jzlsh) => axios.get(`bjgl/cyxj/selectCyxj/${jzlsh}`);
// 新增
DischargeAbstractApi.post = (params) => postDetailApi("bjgl/cyxj/createCyxj", params);
// 删 
DischargeAbstractApi.delete = (id) => deleteDetailApi("bjgl/cyxj/deleteCyxj", id);
// 改 
DischargeAbstractApi.put = (params) => putDetailApi("bjgl/cyxj/updateCyxj", params);

/* *************************** 检验报告 ***********************/
export const InspectionReportApi = {};
// 分页
InspectionReportApi.getPage = (params) => getPageApi("bjgl/lissample/selectPage", params);
// 查 
InspectionReportApi.get = (inspectionId) => getDetailApi("bjgl/lissample/selectCyxj", inspectionId);
// 新增
InspectionReportApi.post = (params) => postDetailApi("bjgl/lissample/createCyxj", params);
// 删 
InspectionReportApi.delete = (inspectionId) => deleteDetailApi("bjgl/lissample/deleteCyxj", inspectionId);
// 改 
InspectionReportApi.put = (params) => putDetailApi("bjgl/lissample/updateCyxj", params);

/* *************************** lis检验表 ***********************/
export const InspectionTableApi = {};
// 查看lis检验表记录
InspectionTableApi.get = (inspectionId) => axios.get(`bjgl/lissample/selectLissample/${inspectionId}`)

/* *************************** 医疗机构 ***********************/
export const institutionsApi = {};
// 分页 /yljg/wsjgList
institutionsApi.getPage = (params) => getPageApi("yljg/wsjgList", params);

// 查 /yljg/{id}
institutionsApi.get = (id) => getDetailApi("yljg", id);

// 删 /yljg/deleteYljgById/{id}
institutionsApi.delete = (id) => deleteDetailApi("yljg/deleteYljgById", id);

// 增 /yljg/creatorYljg
institutionsApi.post = (params) => postDetailApi("yljg/creatorYljg", params);

// 改 /yljg/updateYljg
institutionsApi.put = (params) => putDetailApi("yljg/updateYljg", params);

// 查询所有的医疗机构编码和名称 和id GET /yljg/queryAllYljg
institutionsApi.getAll = () => axios.get("yljg/queryAllYljg");

// 查询医疗机构 搜索 POST /yljg/search
institutionsApi.search = (params) => axios.post("yljg/search", params);

// 查询全部 医疗机构id 和 医疗机构名称 创建用户时使用 GET /yljg/selectAll
institutionsApi.getSelectOption = () => axios.get("yljg/selectAll");

// 查询上级医疗机构 POST /yljg/selectSjYljg
institutionsApi.getParent = (params) => axios.post("yljg/selectSjYljg", params);

// 查询医疗机构要使用的 行政区划 POST /yljg/selectYljgXzqh
institutionsApi.getAdmDivision = (params) =>
    axios.post("yljg/selectYljgXzqh", params);

/* *************************** 机构组 ***********************/
export const institutionsGroupApi = {};
// 分页 /yljgz/yljgZuList
institutionsGroupApi.getPage = (params) =>
    getPageApi("yljgz/yljgZuList", params);

// 查 /yljgz/selectYljgZuById/{id}
institutionsGroupApi.get = (id) => getDetailApi("yljgz/selectYljgZuById", id);

// 删 /yljgz/deleteYljgZuById/{id}
// /yljgz/deleteYljgZuById/{id}
institutionsGroupApi.delete = (id) =>
    deleteDetailApi("yljgz/deleteYljgZuById", id);

// 增 /yljgz/creatYljgZu
institutionsGroupApi.post = (params) =>
    postDetailApi("yljgz/creatYljgZu", params);

// 改  /yljgz/updateYljgZu
institutionsGroupApi.put = (params) =>
    putDetailApi("yljgz/updateYljgZu", params);

// 查询医疗机构组 id 和名称 GET /yljgz/queryYljgZuIdAndZumc
institutionsGroupApi.getSelectOption = () =>
    axios.get("yljgz/queryYljgZuIdAndZumc");
// 查询下级机构 /yljg/selectXjjg/{jgid}
institutionsGroupApi.getSelect = (id) => axios.get(`yljg/selectXjjg/${id}`);

/* *************************** 公告 ***********************/
export const notice = {};
// 分页 /gg/list
notice.getPage = (params) => getPageApi("gg/list", params);

// 查 /gg/{id}
notice.get = (id) => getDetailApi("gg", id);

// 删 /gg/{id}
notice.delete = (id) => deleteDetailApi("gg", id);

// 增 /gg/add
notice.post = (params) => postDetailApi("gg/add", params);

// 改 /gg/update
notice.put = (params) => putDetailApi("gg/update", params);

// 查询当前日期公告 GET /gg/nowGg
notice.getLast = () => axios.get("gg/nowGg");

/* *************************** 登录 ***********************/
export const loginApi = {};

// 用户登录 POST /login
loginApi.login = (params) => postDetailApi("login", params);

// 登出  DELETE /logout
loginApi.logout = () => axios.delete("logout");

// 验证码发送到手机 GET /getCode/{phone}
loginApi.getCode = (phone) => getDetailApi("getCode", phone);

// 手机验证码登录 POST /phoneLogin
loginApi.phoneLogin = (params) => postDetailApi("phoneLogin", params);

// 根据用户名查询用户的医疗机构 POST /selectYhYljg
loginApi.getYljg = (params) => postDetailApi("selectYhYljg", params);

/* *************************** 体检记录 ***********************/
export const PhysicalApi = {};
// 分页
PhysicalApi.getPage = (params) => getPageApi("jktj", params);
// 查单条
PhysicalApi.get = (id) => getDetailApi("jktj", id);

